﻿using System;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using CubeStone.Wang.Utilities.Log;
using NoiseMonitor.Model;
namespace NoiseMonitor.Web.Mvc.Common
{
    public abstract class BaseController : Controller
    {
        protected NoiseMonitorDatabaseContext db;

        /// <summary>
        /// 构造函数
        /// </summary>
        public BaseController()
        {
            db = new NoiseMonitorDatabaseContext();
        }

        /// <summary>
        /// 重写JsonResult的日期返回结果
        /// </summary>
        protected  override  JsonResult Json(object data, string contentType, Encoding contentEncoding, JsonRequestBehavior behavior)
        {
            return new NewJsonResult { Data = data, ContentType = contentType, ContentEncoding = contentEncoding, JsonRequestBehavior = behavior };
        }
       
        /// <summary>
        /// 异常处理
        /// </summary>
        /// <param name="filterContext"></param>
        protected override void OnException(ExceptionContext filterContext)
        {
            LogHelper.WriteErrorLog(filterContext.Exception);
            LogHelper.WriteErrorLog(filterContext.RouteData.Values["controller"]
                + "--------" + filterContext.RouteData.Values["action"]
                + "--------" + filterContext.HttpContext.Request.QueryString
                + "--------" + filterContext.HttpContext.Request.Form);
            // 执行基类中的OnException
            base.OnException(filterContext);
        }
    }
}